//
//  LzwAddressDetailVC.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/4.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwAddressDetailVC.h"
#import "UMSocial.h"

@interface LzwAddressDetailVC ()<UIWebViewDelegate>

@property (nonatomic, retain) UIWebView *myAddWebView;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;

@end

@implementation LzwAddressDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = [self.modleDetailAdd.author objectForKey:@"username"];
    
    UIImage * LandRightBar = [UIImage imageNamed:@"return.png"];
    LandRightBar = [LandRightBar imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:LandRightBar style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction:)];
    
    
    //设置分享按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"100.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonAction:)];
    
    [self.navigationItem.rightBarButtonItem setImageInsets:UIEdgeInsetsMake(5 * WIDTH, 5 * WIDTH, 5 * WIDTH, 5 * WIDTH)];
    
    
    
    
    self.myAddWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 375 * WIDTH, 667 * WIDTH)];
    
    [self.myAddWebView setUserInteractionEnabled:YES];
    [self.myAddWebView setBackgroundColor:[UIColor clearColor]];
    [self.myAddWebView setOpaque:NO];//使网页透明
    
    [self.view addSubview:self.myAddWebView];
    
    NSString *string = self.modleDetailAdd.share_url;

    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:string]];
    [self.view addSubview: self.myAddWebView];
    [self.myAddWebView loadRequest:request];
    
    [self.myAddWebView setDelegate:self];
    
    
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    [view setTag:103];
    [view setBackgroundColor:[UIColor lightGrayColor]];
    [view setAlpha:0.8];
    [self.view addSubview:view];
    
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [self.activityIndicator setCenter:view.center];
    [self.activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [view addSubview:self.activityIndicator];
    [self.view addSubview:self.myAddWebView];
    [view release];
    [_myAddWebView release];
    
}

-(void)webViewDidStartLoad:(UIWebView *)webView{
    
    
    [self.activityIndicator startAnimating];
    
    
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
    [self.activityIndicator stopAnimating];
    UIView *view = (UIView *)[self.view viewWithTag:103];
    [view removeFromSuperview];
    
}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"亲 网络不给力" preferredStyle:UIAlertControllerStyleAlert];
//    
//    
//    [self presentViewController:alert animated:YES completion:^{
//        
//        
//    }];
//    UIAlertAction *ale = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        
//        [self.navigationController popToRootViewControllerAnimated:YES];
//        
//    }];
//    
//    [alert addAction:ale];
//    
    
}

//分享按钮
- (void)shareButtonAction:(UIBarButtonItem *)buto{
    
    //注意：分享到微信好友、微信朋友圈、微信收藏、QQ空间、QQ好友、来往好友、来往朋友圈、易信好友、易信朋友圈、Facebook、Twitter、Instagram等平台需要参考各自的集成方法
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"56911ce367e58e117a002ed8"
                                      shareText:self.modleDetailAdd.share_url
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToRenren, UMShareToTencent,  nil]
                                       delegate:nil];
    
    
    
    
}

//返回按钮触发事件
- (void)leftButtonAction:(UIBarButtonItem *)bar{
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
